import 'package:casdon/core/network/api_client_provider.dart';
import 'package:casdon/modules/feedback/data/api/feedback_type_enum_api.dart';
import 'package:casdon/modules/feedback/data/model/feedback_dialogue_model.dart';
import 'package:casdon/modules/feedback/data/model/feedback_record_model.dart';
import 'package:casdon/modules/feedback/data/repository/feedback_repository.dart';
import 'package:casdon/modules/feedback/data/repository/feedback_repository_impl.dart';
import 'package:casdon/modules/feedback/domain/usecase/feedback_detail_usecase.dart';
import 'package:casdon/modules/feedback/domain/usecase/feedback_list_usecase.dart';
import 'package:casdon/modules/feedback/domain/usecase/feedback_type_list_usecase.dart';
import 'package:casdon/modules/feedback/domain/usecase/finish_feedback_usecase.dart';
import 'package:casdon/modules/feedback/domain/usecase/reply_feedback_usecase.dart';
import 'package:casdon/modules/feedback/domain/usecase/submit_feedback_usecase.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

final feedbackRepositoryProvider = Provider<FeedbackRepository>(
  (ref) => FeedbackRepositoryImpl(ref.read(apiClientProvider)),
);

final feedbackTypeListUsecaseProvider = Provider(
  (ref) => FeedbackTypeListUsecase(ref.read(feedbackRepositoryProvider)),
);

final feedbackTypeListProvider =
    FutureProvider.autoDispose<List<ResponseFeedbackTypeEnum>>((ref) async {
  return ref.read(feedbackTypeListUsecaseProvider).execute();
});

final submitFeedbackUsecaseProvider = Provider(
  (ref) => SubmitFeedbackUsecase(ref.read(feedbackRepositoryProvider)),
);

final feedbackListUsecaseProvider = Provider(
  (ref) => FeedbackListUsecase(ref.read(feedbackRepositoryProvider)),
);

final feedbackListProvider =
    FutureProvider.autoDispose<List<FeedbackRecordModel>>((ref) async {
  return ref.read(feedbackListUsecaseProvider).execute();
});

final feedbackDetailUsecaseProvider = Provider(
  (ref) => FeedbackDetailUsecase(ref.read(feedbackRepositoryProvider)),
);

final finishFeedbackUsecaseProvider = Provider(
  (ref) => FinishFeedbackUsecase(ref.read(feedbackRepositoryProvider)),
);

final replyFeedbackUsecaseProvider = Provider(
  (ref) => ReplyFeedbackUsecase(ref.read(feedbackRepositoryProvider)),
);

final feedbackDialogueListProvider = FutureProvider.autoDispose.family<
    List<FeedbackDialogueModel>, String>((ref, feedbackInfoId) async {
  return ref
      .read(feedbackDetailUsecaseProvider)
      .execute(feedbackInfoId);
});
